from os import system

def main():
    ps_cmd = "ps -ef | grep "+ "\"" + "crawler\.py" + "\""    # shell command which querys the correspond process
    run_cmd = "./crawler.py"   # shell command which run the python script
    while True:
        status = system(ps_cmd)  # get the return value of ps_cmd

        # display the return value of ps_cmd, 0 is runninng, 256(value of "2" in hexadecimal) is finish
        print("the ps_mod return code: %d" %(status))
        if status == 0: # value 0 is return value of "ps -ef" command means that the process is running
            print("the process is running currently")
        else:
            print("the process is finish, now we restart it!")
            system(run_cmd)  # restart the program "crawler.py"

if __name__ == '__main__':
    main()